/*
 * @Author: weidewei
 * @Date: 2025-05-16 15:13:42
 * @LastEditors: weidewei
 * @LastEditTime: 2025-05-16 15:50:46
 * @Description:
 * @FilePath: \v2\src\http\index.js
 */
// src/utils/request.js
import axios from "axios";

// 创建 axios 实例
const service = axios.create({
  baseURL: "/api",
  timeout: 5000,
});
// 请求拦截器
service.interceptors.request.use((config) => {
  // 可在此处添加 token
  // config.headers['Authorization'] = 'Bearer ' + getToken()
  return config;
});

// 响应拦截器
service.interceptors.response.use(
  (response) => {
    const res = response.data;
    // if (res.code !== 200) {
    //   return Promise.reject(new Error(res.message || "Error"));
    // }
    return res;
  },
  (error) => {
    return Promise.reject(error);
  }
);

export function commonFetch(method, url, data, options) {
  if(method === "get") {
    return service[method](url, {
      params: data,
      ...options
    })
  }
  return service[method](url, data, options)
}

export function requestGet(url,data,options) {
  return commonFetch('get',url,data,options)
}
export function requestPost(url,data,options) {
  return commonFetch('post',url,data,options)
}



export default service;
